*&---------------------------------------------------------------------*
*& Report ztest03
*&---------------------------------------------------------------------*

report z_alv_test.

types: begin of ty_sflight.
         include type sflight.
types:   color type lvc_t_scol, " color 字段保存颜色设置
       end of ty_sflight.

data gt_sflight type standard table of ty_sflight.
data lo_column_price   type ref to cl_salv_column_table.

start-of-selection.
  select *
    into corresponding fields of table gt_sflight
    from sflight.

  try.
      cl_salv_table=>factory(
        importing   r_salv_table   = data(lo_salv)
        changing    t_table        = gt_sflight
      ).
    catch cx_salv_msg.
  endtry.

  " 设置工具栏
  lo_salv->get_functions(  )->set_all(  ).

  lo_salv->get_display_settings(  )->set_list_header( '航班' ).

  loop at gt_sflight assigning field-symbol(<fs_sflight>).
    if <fs_sflight>-price > 1000.
      append
        value lvc_s_scol( fname = 'PRICE' color-col = 5 color-int = 1 color-inv = 0 )
        to <fs_sflight>-color.
    endif.
  endloop.

  lo_salv->get_columns( )->set_color_column( 'COLOR' ).

  lo_salv->display(  ).